package com.demo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.function.Predicate;

public class Main {

    public static List<Apple> filterApples(List<Apple> inventory, Predicate<Apple> p) {
        List<Apple> result = new ArrayList<>();
        for(Apple apple: inventory) {
            if (p.test(apple)) {
                result.add(apple);
            }
        }
        return result;
    }

    public static void main(String[] args) {
        List<Apple> inventory = Util.getApples();
        List<Apple> result = filterApples(inventory, Apple::isGreenApple);
        System.out.println(result);
        result = filterApples(inventory, Apple::isHeavyApple);
        System.out.println(result);
        result = filterApples(inventory, (Apple a) -> a.getWeight() < 80);
        System.out.println(result);
    }
}
